package cn.shadowsouls.common.handler;

import cn.shadowsouls.common.domain.AjaxResult;
import cn.shadowsouls.common.exception.DefinitionException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author shadowsouls
 * @version 1.0
 */
@ControllerAdvice
public class GlobalExceptionHandler {
    /**
     * 处理自定义异常
     */
    @ExceptionHandler(value = DefinitionException.class)
    @ResponseBody
    public AjaxResult bizExceptionHandler(DefinitionException e) {
        return AjaxResult.error(e);
    }

    /**
     * 处理其他异常
     */
    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public AjaxResult exceptionHandler(Exception e) {
        return AjaxResult.error(e.getMessage());
    }
}


